/*
 * @Author: TT-hzy 
 * @Date: 2024-06-27 11:50:22
 * @LastEditors: TT-hzy 
 * @LastEditTime: 2024-07-03 11:49:06
 * @Description: 
 */
import { EggAppConfig, PowerPartial } from 'egg';


export type DefaultConfig = PowerPartial<EggAppConfig>;

export default (appInfo: EggAppConfig) => {
  const config = {} as PowerPartial<EggAppConfig>;


  config.keys = appInfo.name + '_1719394746648_5292';

  // add your middleware config here
  config.middleware = [
    "errorHandler",

  ];

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  // 允许跨域
  config.cors = {
    origin: '*',
    allowMethods: 'GET,HEAD,PUT,POST,DELETE',
  };


  config.security = {
    // 关闭csrf
    csrf: {
      enable: false,
    },
    domainWhiteList: ['http://localhost:8080'],
  };
  // jwt校验用户登录
  config.jwt = {
    secret: '123456', // 加密密钥


  };
  // 验证参数
  config.valparams = {
    locale: 'zh-cn',
    throwError: true
  };
  // 数据库配置
  config.sequelize = {
    dialect: 'mysql',
    database: "egg-ts-doc-default",
    host: 'localhost',
    port: 3306,
    username: 'root',
    password: 'r_123456',
    timezone: '+08:00',
    define: {
      // 注意需要加上这个， egg-sequelize只是简单的使⽤Object.assign对配置和默认配置做了merge, 如果不加这个 update_at会被转变成 updateAt故报错
      underscored: true,
      // // 禁⽌修改表名，默认情况下，sequelize将⾃动将所有传递的模型名称（define的第⼀个参数）转换为复数
      // // 但是为了安全着想，复数的转换可能会发⽣变化，所以禁⽌该⾏为
      freezeTableName: true,

      // 自动写入时间戳 created_at updated_at
      timestamps: true,

      paranoid: false,

    },
  };
  return {
    ...config,
    ...userConfig,
  };
};
